#ifndef pen_tool_H
#define pen_tool_H

#include "tool.h"

class Page;
class QPainterPath;
class QGraphicsPathItem;

/**
 * The tool used for free hand drawing on a page.
 */
class Pen : public Tool
{
    Q_OBJECT

public:
    /**
     * Create a new pen.
     * @param parent The parent object of this pen.
     */
    Pen(QObject *parent=0);

private:
    /**
     * A reference to the page where the drawing was started.
     * Used as an indicator, if the pen is "pressed" down.
     */
    Page *m_page;

    /**
     * The Path that is drawn on the page.
     */
    QGraphicsPathItem *m_path;

    /**
     * The path that is the backend for the drawn path.
     *
     * Points are added to this path and it is then set as the path
     * for the QGraphicsItem.
     * Working on the reference that QGraphicsPathItem provides
     * does not work.
     */
    QPainterPath *m_painterPath;

    /**
     * The minimum manhattan-distance that a new point has to have
     * to the previous one to be added to the path.
     */
    static const int MIN_DISTANCE = 2;

    /**
     * Add this point to the current path.
     * @param point The global coordinates of this point. Taken from the event.
     * @param document The document that received the event.
     */
    void addPoint(QPoint point, Document *document);

public slots:
    /**
     * Starts a new path when the tool is pressed on a page.
     */
    void mousePressEvent(QMouseEvent *event, Document *document);

    /**
     * Add a new point to the path when over a page.
     */
    void mouseMoveEvent(QMouseEvent *event, Document *document);

    /**
     * Finishes the path.
     */
    void mouseReleaseEvent(QMouseEvent *event, Document *document);
};

#endif